package com.lianniu.web.tea.user.collect.service.impl;

import java.util.HashMap;
import java.util.Map;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.lianniu.web.base.BaseResult;
import com.lianniu.web.tea.user.collect.dao.TeaCollectDao;
import com.lianniu.web.tea.user.collect.model.TeaCollect;
import com.lianniu.web.tea.user.collect.service.ITeaUserCollectService;
import com.lianniu.web.util.UUIDUtil;

@Service
@Transactional
public class TeaUserCollectServiceImpl implements ITeaUserCollectService {

	private final static Logger logger = Logger.getLogger(TeaUserCollectServiceImpl.class);

	@Autowired
	private TeaCollectDao teaCollectDao;
	
	public BaseResult addCollect(TeaCollect teaCollect) {
		logger.info("TeaUserCollectServiceImpl addCollect start");
		String id = UUIDUtil.getUUID();
		teaCollect.setId(id);
		teaCollectDao.insert(teaCollect);
		logger.info("TeaUserCollectServiceImpl addCollect end");
		return BaseResult.success(teaCollect);
	}

	
	public BaseResult deleteCollect(String id) {
		logger.info("TeaUserCollectServiceImpl deleteCollect start");
		teaCollectDao.deleteByPrimaryKey(id);
		logger.info("TeaUserCollectServiceImpl deleteCollect end");
		return BaseResult.success();
	}


	@Override
	public BaseResult checkCollect(String productId, String userId) {
		logger.info("TeaUserCollectServiceImpl checkCollect start");
		Map param = new HashMap();
		param.put("productId", productId);
		param.put("userId", userId);
		String id = teaCollectDao.checkCollect(param);
		logger.info("TeaUserCollectServiceImpl checkCollect end");
		return BaseResult.success(id);
	}

}
